package fm.dongman.modellib.local;

import android.content.Context;
import android.util.Log;

import java.util.List;

import fm.dongman.animefm.contractlib.BaseDataSource;
import fm.dongman.animefm.contractlib.IModel;
import fm.dongman.animefm.contractlib.contract.ComicContract;
import fm.dongman.animefm.contractlib.model.ComicDataModel;

/**
 * 番剧页面本地数据源加载
 * Created by KUIGE on 2017/10/17.
 */

public class ComicLocalDataSource implements ComicContract.IComicDataSource {

    private static ComicLocalDataSource SINGLETON;

    private DataOperationHelper mOperationHelper;

    private ComicLocalDataSource(Context context)
    {
        mOperationHelper = DataOperationHelper.getDataOperationHelper(context);
    }

    public static ComicLocalDataSource getInstance(Context context) {
        if (SINGLETON == null)
        {
            SINGLETON = new ComicLocalDataSource(context);
        }
        return SINGLETON;
    }

    @Override
    public void getComicGuessLike(BaseDataSource.LoadSourceCallback<? super List<? extends IModel.IComicModel>> callback) {

    }

    @Override
    public void getData(BaseDataSource.LoadSourceCallback<? super ComicDataModel> callback) {
        ComicDataModel model = mOperationHelper.downComicDatas();
        Log.e("番剧页面数据数量",model.getNewComics().size()+""+model.getNewComment().size()+model.getRecommendComics().size());
        callback.onDataLoaded(model);
    }

    @Override
    public void saveData(ComicDataModel dataModel) {
        mOperationHelper.addComic_newComics(dataModel.getNewComics());
        mOperationHelper.addComic_newComment(dataModel.getNewComment());
        mOperationHelper.addComic_recommendComics(dataModel.getRecommendComics());
    }

    @Override
    public void refreshData() {

    }

    @Override
    public void offLine() {

    }
}
